package com.zlt.controller.seeker;

import com.alibaba.fastjson.JSON;
import com.zlt.controller.BaseController;
import com.zlt.service.OfferService;
import com.zlt.service.impl.OfferServiceImpl;
import com.zlt.vo.Result;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sound.midi.SoundbankResource;
import java.io.IOException;

@WebServlet("/seeker/office/*")
public class OfferController extends BaseController {

    private OfferService service = new OfferServiceImpl();

    @Override
    protected void defaultMethod(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { }

    protected Result chick(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{

        String token = req.getHeader("token");
        String oid = req.getParameter("oid");
        String chick = req.getParameter("chick");

        try {
            boolean suc = service.chickOffer(token,oid,chick);
            return suc==true ? Result.ok("操作成功"):Result.error("操作失败");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(e.getMessage());
        }

    }

    protected Result show(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
        String token = req.getHeader("token");

        try {
            return Result.ok("查询成功", JSON.toJSON(service.showOffer(token)));
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(e.getMessage());
        }
    }
}
